<?php

class CMS_Application_Resource_Mail extends Zend_Application_Resource_ResourceAbstract
{
    const DEFAULT_REGISTRY_KEY = 'mail_config';

    public function init()
    {
        $options = $this->getOptions ();
        
        $transportType = ucfirst ( strtolower ( $options ['protocol'] ) );
        $transportHost = $options ['host'];
        $transportOptions = $options ['options'];
        
        $transportClass = "Zend_Mail_Transport_{$transportType}";
        
        $transport = new $transportClass ( $transportHost, $transportOptions );
        Zend_Mail::setDefaultTransport ( $transport );
        
        if (isset ( $options ['registry'] ))
        {
            if (isset ( $options ['registryKey'] ))
            {
                $registryKey = $options ['registryKey'];
            } else
            {
                $registryKey = self::DEFAULT_REGISTRY_KEY;
            }
            Zend_Registry::set ( $registryKey, $options ['registry'] );
        }
    }
}
?>